package c.c0der.jsgl.jso;

import android.opengl.GLES20;

import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.annotations.JSFunction;

public class JSObjectGL20 extends ScriptableObject {
    public JSObjectGL20() {
        putProperty(this, "VERTEX_SHADER", GLES20.GL_VERTEX_SHADER);
        putProperty(this, "FRAGMENT_SHADER", GLES20.GL_FRAGMENT_SHADER);
    }

    @Override
    public String getClassName() {
        return "gl";
    }

    @JSFunction
    public int createShader(int type) {
        return GLES20.glCreateShader(type);
    }

    @JSFunction
    public void shaderSource(int shader,
                             String string) {
        GLES20.glShaderSource(shader, string);
    }

    @JSFunction
    public void compileShader(int shader) {
        GLES20.glCompileShader(shader);
    }

    @JSFunction
    public int createProgram() {
        return GLES20.glCreateProgram();
    }

    @JSFunction
    public void attachShader(int program,
                             int shader) {
        GLES20.glAttachShader(program, shader);
    }

    @JSFunction
    public void linkProgram(int program) {
        GLES20.glLinkProgram(program);
    }

    @JSFunction
    public void useProgram(int program) {
        GLES20.glUseProgram(program);
    }

    @JSFunction
    public void drawArrays(int mode,
                           int first,
                           int count) {
        GLES20.glDrawArrays(mode, first, count);
    }

    @JSFunction
    public void clearColor(int red,
                           int green,
                           int blue,
                           int alpha) {
        GLES20.glClearColor((float) red / 100.0f, (float) green / 100.0f, (float) blue / 100.0f, (float) alpha / 100.0f);
    }
}
